#!/usr/bin/env python
#coding=utf-8

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcore.auth.credentials import AccessKeyCredential
from aliyunsdkcore.auth.credentials import StsTokenCredential
from aliyunsdkalidns.request.v20150109.AddDomainRecordRequest import AddDomainRecordRequest

#云解析，解析域名方法
def aliParsing(key,secret,domain,domain_rr,domain_type,value):
    credentials = AccessKeyCredential(key, secret)
    # use STS Token
    # credentials = StsTokenCredential('<your-access-key-id>', '<your-access-key-secret>', '<your-sts-token>')
    client = AcsClient(region_id='cn-shanghai', credential=credentials)

    request = AddDomainRecordRequest()
    request.set_accept_format('json')

    request.set_DomainName(domain)
    request.set_RR(domain_rr)
    request.set_Type(domain_type)
    request.set_Value(value)

    response = client.do_action_with_exception(request)
    # python2:  print(response) 
    print(str(response, encoding='utf-8'))
